package com.nl.pulsardemo.not.reader;

import org.apache.pulsar.client.api.*;

/**
 * @author : ZhaoY
 * @description : 读者(Reader)
 * @date : 2021-01-26 15:04
 **/
public class ReaderDemo {
    //Pulsar集群中broker的serviceUrl
    private static String brokerServiceUrl = "pulsar://10.1.8.68:6650,10.1.8.64:6650";
    //指定topic name
    private static String topicName = "persistent://public/default/my-topic";

    public static void main(String[] args) throws PulsarClientException {
        //构造Pulsar client
        PulsarClient client = PulsarClient.builder()
                .serviceUrl(brokerServiceUrl)
                .build();

        //创建reader(读者)
        Reader<byte[]> reader = client.newReader()
                .topic(topicName)
                .startMessageId(MessageId.earliest)
                .create();
    while (true){
        Message message=reader.readNext();
        System.err.println("-==-="+message);
    }
    }
}